<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="demo">
        <ul>
            <!-- 数组的渲染 -->
            <li v-for="(item,index) in persons" :key="item.id">
                {{item.id}}---{{item.name}}---{{item.age}}
                <button @click="deleteP(index)">删除</button>
                <button @click="updataP(index,{id:item.index,name:'林冲',age:26})">更新</button>
            </li>
            <hr>
            <!-- 对象的渲染 -->
            <li v-for='(value,key) in persons[5]' :key="key">
                {{key}}={{value}}
            </li>
        </ul>
    </div>
    <script src="../day02/js/vue.js"></script>
    <script>
        /* 
        列表的渲染方式有两种，一种是渲染数组，一种是渲染对象
        */
        new Vue({
            el:'#demo',
            data:{
                persons:[
                    {id:1,name:'宋江',age:32},
                    {id:2,name:'花荣',age:24},
                    {id:3,name:'关胜',age:30},
                    {id:4,name:'晁盖',age:38},
                    {id:5,name:'鲁智深',age:35},
                    {id:6,name:'卢俊义',age:31},
                    {id:7,name:'杨志',age:27},
                    {id:8,name:'武松',age:25},
                ]
            },
            methods:{
                deleteP(index){
                    this.persons.splice(index,1);
                }, 
                updataP(index,newP){
                    // this.persons.splice(index,1,newP);
                    this.persons[index].name = newP.name;
                    this.persons[index].age = newP.age;
                }
            }
        })
    </script>
</body>
</html>